/*
 * @Description: 测试数据
 * @Author: yingying.fan
 * @Date: 2019-05-13 14:22:21
 * @Last Modified by: yingying.fan
 * @Last Modified time: 2019-05-14 17:41:26
 */

import StationInfoModel from '../model/StationInfoModel'
import BusInfoModel from '../model/BusInfoModel'

// 设置了到站提醒的站点列表 STATION_SORT 站点序号
let attentionStationList = [
  { LINE_ID: '12', LINE_TYPE: 1, STATION_ID: '121', STATION_SORT: 12 }
]
// 设置了下车提醒的车辆列表
let attentionBusList = [{ LINE_ID: '12', LINE_TYPE: 1, BUS_ID: '1112' }]

/**
 * 根据线路id获取站点列表
 * @param {Number} routeId 线路Id
 * @param {Number} direction 方向
 */
function getStationListByRouteId(routeId = 12, direction = 1) {
  return new Promise((resolve, reject) => {
    let list = []
    for (let i = 0; i < 10; i++) {
      let station = {
        stationId: '12' + i,
        stationName: '站点' + i
      }
      list.push(station)
    }
    routeId = routeId + ''
    let modelList = []
    list.map(station => {
      let stationModel = new StationInfoModel(
        station.stationId,
        station.stationName
      )
      attentionStationList.find(attentionStation => {
        if (
          attentionStation.LINE_ID === routeId &&
          attentionStation.LINE_TYPE === direction &&
          attentionStation.STATION_ID === stationModel.stationId
        ) {
          stationModel.setStationAttention(true)
          return true
        }
      })
      modelList.push(stationModel)
    })
    setTimeout(() => {
      resolve(modelList)
    }, 50)
  })
}

let getBusTime = 0
/**
 * 根据线路id获取该条线路下的所有公交
 * @param {Number} routeId 线路Id
 * @param {Number} direction 方向 1上行，2下行
 * @param {String} longitude 经度
 * @param {String} latitude 维度
 */
function getBusListByRouteId(routeId = 12, direction = 1, longitude, latitude) {
  console.log('获取公交数据', getBusTime)
  let k = getBusTime % 10
  getBusTime++
  return new Promise((resolve, reject) => {
    let list = []
    for (let i = 0; i < 3; i++) {
      let station = {
        stationId: '12' + (i + k + 2),
        busId: '111' + i,
        isArrived: i % 2 === 0 ? 1 : 2
      }
      list.push(station)
      if (i % 2 === 0) {
        let station2 = {
          stationId: '12' + (i + k + 2),
          busId: '112' + i
        }
        list.push(station2)
      }
      k++
    }
    routeId = routeId + ''
    let modelList = []
    list.map(bus => {
      let busModel = new BusInfoModel(bus.busId, bus.stationId, bus.isArrived)
      attentionBusList.find(attentionStation => {
        if (
          attentionStation.LINE_ID === routeId &&
          attentionStation.LINE_TYPE === direction &&
          attentionStation.BUS_ID === busModel.busId
        ) {
          busModel.setBusAttention(true)
          return true
        }
      })
      modelList.push(busModel)
    })
    setTimeout(() => {
      resolve(modelList)
    }, 100)
  })
}

export { getStationListByRouteId, getBusListByRouteId }
